﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dzs.Web.Admin.monthsked
{
    public partial class Listmonth : Web.Admin.BasePage
    {
        Maticsoft.BLL.monthSupplayPlan bll = new Maticsoft.BLL.monthSupplayPlan();        
        BLL.configinfo bc = new BLL.configinfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Model.configinfo c = bc.GetModel();
                //lblmsg.Text = c.psbz.Value.ToString();
                //int nums = bll.GetRecordCount(" user_id is null ");
                //if (DateTime.Now.Day > c.psbz.Value && nums > 0)
                //    lblmsg.Text += "分配日期已过，还有未分配的任务请及时分配！";
                BindData();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }       

        #region gridView

        public void BindData()
        {
           

            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            if (txtKeyword.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and sname like '%{0}%'", txtKeyword.Text.Trim());
            }
            if (txtKeyword2.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and projectname like '%{0}%'", txtKeyword2.Text.Trim());
            }
            if (txtwinbid.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and winbid like '%{0}%'", txtwinbid.Text.Trim());
            }   
            strWhere.Append(" and arrivalAddress is not null order by sname");
            ds = bll.GetListnums(strWhere.ToString());
            gridView.DataSource = ds;
            gridView.DataBind();
        }

        protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridView.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //#warning 代码生成警告：请检查确认真实主键的名称和类型是否正确
            //int ID = (int)gridView.DataKeys[e.RowIndex].Value;
            //bll.Delete(ID);
            //gridView.OnBind();
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < gridView.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)gridView.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确
                    if (gridView.DataKeys[i].Value != null)
                    {
                        idlist += gridView.DataKeys[i].Value.ToString() + ",";
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }

        #endregion

        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl_isGoodsQualityStatus = e.Row.FindControl("lbl_isGoodsQualityStatus") as Label;

                Label lbl_goodsQualityStatus = e.Row.FindControl("lbl_goodsQualityStatus") as Label;

                CheckBox cb = e.Row.FindControl("DeleteThis") as CheckBox;

                if (lbl_isGoodsQualityStatus.Text == "False")
                {
                    lbl_isGoodsQualityStatus.Text = "否";
                    cb.Enabled = true;
                }
                else
                {
                    lbl_isGoodsQualityStatus.Text = "是";
                    if (!string.IsNullOrEmpty(lbl_goodsQualityStatus.Text))
                    {
                        cb.Enabled = true;
                    }
                    else
                    {
                        cb.Enabled = false;
                    }

                }

            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string idlist = GetSelIDlist();
            if (idlist.Trim().Length == 0)
                return;
            string[] ids = idlist.Split(',');
            foreach (string id in ids)
            {
            int   monthsupplyid = int.Parse(id);
            string spotunit = this.txtspotunit.Text;
            string spottype = this.txtspottype.Text;
            decimal spotnum = decimal.Parse(this.txtspotnum.Text);
            string spotcontent = this.txtspotcontent.Text;           
            DateTime plandate = DateTime.Parse(this.txtplandate.Text);            

            dzs.Model.monthsked model = new dzs.Model.monthsked();
            model.spotunit = spotunit;
            model.spottype = spottype;
            model.spotnum = spotnum;
            model.spotcontent = spotcontent;            
            model.plandate = plandate;            
            model.monthsupplyid = monthsupplyid;
            dzs.BLL.monthsked bll = new dzs.BLL.monthsked();
            bll.Add(model);
            }
            Maticsoft.Common.MessageBox.Show(this, "抽检成功!");
        }
    }
}